package com.fcy.teamwork.business.login

import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.fcy.teamwork.base.*
import com.fcy.teamwork.business.main.MainAct
import com.fcy.teamwork.databinding.ActivityLoginBinding
import kotlinx.coroutines.launch

class LoginAct : BaseActivity<ActivityLoginBinding>() {
    private val vm: LoginVM by viewModels()
    override fun initBinding() = ActivityLoginBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.btnLogin.noFastCLick(3000) {
            log("hahahahah!!!!")
            lifecycleScope.launch {
                val result =
                    vm.login(binding.etUsername.text.toString(), binding.etPwd.text.toString())
                if (result) {
                    toActivity(MainAct::class.java)
                } else {
                    toast("用户名或密码错误")
                }
            }
        }
    }

}